package com.example.mapp;

import com.example.entity.supervision.PublicRandom;
import com.example.entity.supervision.PublicRandomResult;
import com.example.mapp.buildSql.SupervisionMappSql;
import com.example.mapp.buildSql.SysUserMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * Created by simon on 2018/9/10.
 */
@Mapper
public interface PublicRandomMapp {

    @Insert(" insert into public_random (pr_name,pr_party_id,pr_party_name,created_user_id,created_time) " +
            " value (#{prName},#{prPartyId},#{prPartyName},#{createdUserId},#{createdTime}) ")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
    int insert(PublicRandom promotion) throws Exception;

    @Delete(" delete from public_random where id=#{id} ")
    int delete(PublicRandom promotion) throws Exception;


    @Update(" update public_random set pr_name=#{prName}  where id=#{id} ")
    int update(PublicRandom promotion) throws Exception;

    @Update(" update public_random set finish='1' where id=#{id} ")
    int updateState(Map map) throws Exception;

    @SelectProvider(type = SupervisionMappSql.class, method = "queryPublicRandom")
    List<PublicRandom> query(PublicRandom promotion) throws Exception;

    @Insert(" insert into public_random_result " +
            " (public_random_id,be_cked_party_id,be_cked_party_name,rspon_user_id,rspon_user_name " +
            " ,rspon_party_id,rspon_party_name,be_party_type) " +
            " value (#{publicRandomId},#{beCkedPartyId},#{beCkedPartyName},#{rsponUserId},#{rsponUserName}" +
            " ,#{rsponPartyId},#{rsponPartyName},#{bePartyType} ) ")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = Long.class)
    int addRes(PublicRandomResult publicRandomResult) throws Exception;

    @Select(" select * from public_random_result where public_random_id = #{prID}  ")
    List<PublicRandomResult> queryRes(Map queryRes) throws Exception;

    /**
     * 当市 、局级单位获取部门
     * @param id
     * @return
     */
    @Select(" select id as 'id',party_name as 'partyName' from party where (parent_id=#{id} or id=#{id} )  and party_type='4' ")
    List<Map<String,Object>> findUnitCity(String id);

    /**
     * 分局级单位获取部门
     * @param id
     * @return
     */
    @Select(" select id as 'id',party_name as 'partyName' from party where id=#{id} ")
    List<Map<String, Object>> findUnitArea(String id);


    /**
     * 通过单位id获取用户信息
     * @param map
     * @return
     */
    @SelectProvider(type = SysUserMappSql.class, method = "queryUserByUnit")
    List<Map<String, Object>> queryUserByUnit(Map map);

    @Select(" select * from public_random where id=#{id} ")
    PublicRandom findState(PublicRandom random);
}
